package getWay

import "github.com/gin-gonic/gin"

type Error struct {
	Code    State
	SubCode string
	SubMsg  string
}

type SError struct {
	Code    State
	SubCode string
	SubMsg  string
}

func ExceptionGetWayCatch(c *gin.Context) {
	err := recover() //获取异常
	if err != nil {
		switch err.(type) {
		case Error:
			e := (err).(Error)
			FailGetWay(c, e.Code, e.SubCode, e.SubMsg)
			break
		case SError:
			e := (err).(SError)
			SuccessGetWay(c, e.Code, e.SubCode, e.SubMsg)
			break
		}
	}
}

func ThrowsGetWayErr(code State, subCode, subMsg string) {
	panic(Error{Code: code, SubCode: subCode, SubMsg: subMsg})
}

func ThrowsGetWaySErr(code State, subCode, subMsg string) {
	panic(SError{Code: code, SubCode: subCode, SubMsg: subMsg})
}

func AssertThrowsGetWayErr(throwable bool, code State, subCode, subMsg string) {
	if throwable {
		ThrowsGetWayErr(code, subCode, subMsg)
	}
}

func AssertThrowsGetWaySErr(throwable bool, code State, subCode, subMsg string) {
	if throwable {
		ThrowsGetWaySErr(code, subCode, subMsg)
	}
}
